﻿using System.ComponentModel.Composition;
using System.Web;
using ASPItalia.ModelVirtualCasting.EntityFramework.Wrappers;
using ASPItalia.ModelVirtualCasting.Parts;

namespace ASPItalia.ModelVirtualCasting.EntityFramework
{
    [Export(typeof(IContextContainer))]
    [PartCreationPolicy(CreationPolicy.NonShared)]
    public class ContextContainer : IContextContainer
    {
        private IContextContainer _container = null;

        public ContextContainer()
        {
            if (HttpContext.Current.IsNull())
            {
                _container = new ThreadContextContainer();
            }
            else
            {
                _container = new WebContextContainer();
            }
        }

        public ContextWrapper Current
        {
            get { return _container.Current; }
        }

        public void Clear()
        {
            _container.Clear();
        }
    }
}